package com.itqf.controller;

import com.itqf.entity.TbItem;
import com.itqf.entity.Users;
import com.itqf.entity.UsersList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Arrays;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/20
 * @Time: 上午10:14
 */
@Controller
//@RequestMapping("/user")
public class MyParameterController {

    //http://localhost:8080/del?id=1
    @RequestMapping("/del")
    public  String delete(int id){//方法参数名和url中参数名一致
        System.out.println("delete .... id="+id);
        return "/jsp/success.jsp";
    }

    //   get:  //http://localhost:8080/user/1  查
    //  delete   //http://localhost:8080/user/1  删除
    //   put:  //http://localhost:8080/user/1..  修改
    //  post   //http://localhost:8080/user/1..  新增

    @RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE)
    //public  String delete1(@PathVariable("id") int uid){
    //@PathVariable  得到请求路径占位符位置的值  如果占位符变量和参数一致 那么就可省略
    public  String delete1(@PathVariable int id){
        System.out.println("delete 删 id="+id);
        return "/jsp/success.jsp";
    }
    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    //public  String delete1(@PathVariable("id") int uid){
    //@PathVariable  得到请求路径占位符位置的值  如果占位符变量和参数一致 那么就可省略
    public  String findById(@PathVariable int id){
        System.out.println("get  查  id="+id);
        return "/jsp/success.jsp";
    }


    //http://localhost:8080/add?id=1&name=zhangsan
    @RequestMapping("/add")
    public  String add(int id,String name){
        System.out.println("add .... id="+id+",name="+name);
        return "/jsp/success.jsp";
    }

    
    //http://localhost:8080/addItem?title=zhangsan&price=100&sellPoint=aa&num=10
    @RequestMapping("/addItem")
    public  String addItem(TbItem item){//对象的属性和前端请求的参数一致
        System.out.println("addItem .... "+item);
        //tbItemService.add(item);
        return "/jsp/success.jsp";
    }


    //不规范
    // 包：都是小写   类：首字母大写  变量：驼峰式


//    @RequestMapping("/doRegister")
//    public String doReg(String name,String[]hobby){
//        System.out.println(name+"--"+Arrays.toString(hobby));
//        return "/jsp/success.jsp";
//    }

    @RequestMapping("/doRegister")
    public String doReg(Users users){
        System.out.println(users.getName()+"--"+Arrays.toString(users.getHobby()));
        return "/jsp/success.jsp";
    }


    @RequestMapping("/doRegister1")
    //多对象  了解
    public String doReg1(UsersList usersList){
        System.out.println(usersList);
        return "/jsp/success.jsp";
    }
}
